//
//  WarnDetailsFooterView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/2.
//

#import "WarnDetailsFooterView.h"
#import "VoiceView.h"
#import "SYAudio.h"

@interface WarnDetailsFooterView ()

@property (nonatomic ,strong) UIView * GJview;
@property (nonatomic ,strong) UIView * GJBackview;

@property (nonatomic ,strong) UIView * CLview;
@property (nonatomic ,strong) UIView * CLBackview;


@property (nonatomic,strong) NSTimer * timer;
@property (nonatomic, assign) int timeS;
@property (nonatomic ,strong) UIButton * playBtn;
@end

@implementation WarnDetailsFooterView


+ (instancetype)NewView {
    WarnDetailsFooterView * view = [WarnDetailsFooterView new];
    view.clipsToBounds = YES;
    view.backgroundColor = UIColor.clearColor;
    [view newUI];
    return view;
}
- (void)newUI{
    
    UIView * GJview = [UIView new];
    self.GJview = GJview;
    [DTKTool YJ:kwt(7) andView:GJview];
    GJview.backgroundColor = UIColor.whiteColor;
    [self addSubview:GJview];
    [GJview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(8));
        make.top.offset(0);
        make.right.offset(kwt(-8));
        make.height.offset(kwt(200));
    }];
    
 
    UILabel * temp1 = [DTKTool labelWithText:@"告警数据" andFont:kCFont(19) andTextColor:KcolorHex(@"#222222")];
    [GJview addSubview:temp1];
    [temp1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(15));
        make.height.offset(kwt(19));
    }];
    
    UIView * GJBackview = [UIView new];
    self.GJBackview = GJBackview;
    [GJview addSubview:GJBackview];
    [GJBackview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(48));
        make.bottom.offset(0);
    }];
    
    
    UIView * CLview = [UIView new];
    self.CLview = CLview;
    [DTKTool YJ:kwt(7) andView:CLview];
    CLview.backgroundColor = UIColor.whiteColor;
    [self addSubview:CLview];
    [CLview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(8));
        make.top.equalTo(GJview.mas_bottom).offset(kwt(10));
        make.right.offset(kwt(-8));
        make.height.offset(kwt(200));
    }];
    
    UILabel * temp11 = [DTKTool labelWithText:@"处理记录" andFont:kCFont(19) andTextColor:KcolorHex(@"#222222")];
    [CLview addSubview:temp11];
    [temp11 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(15));
        make.height.offset(kwt(19));
    }];
    
    UIView * CLBackview = [UIView new];
    self.CLBackview = CLBackview;
    [CLview addSubview:CLBackview];
    [CLBackview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(48));
        make.bottom.offset(0);
    }];
}

-(void)setModel:(WarnModel *)model{
    _model = model;
    MJWeakSelf
    ///先写告警
    [self.GJBackview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    ///1:打卡数值 2：任务数据 3：文字备注
    if(model.alarmDataType == 3){
        if(model.alarmData.data.length > 0){
            UILabel * lab = [DTKTool labelWithText:model.alarmData.data andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
            lab.numberOfLines = 0;
            [self.GJBackview addSubview:lab];
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(kwt(12));
                make.top.offset(0);
                make.right.offset(kwt(-12));
            }];
            if(model.alarmData.remark.length > 0){
                UIView * line = [UIView new];
                line.backgroundColor = KcolorHex(@"#DEDEDE");
                [self.GJBackview addSubview:line];
                [line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(kwt(12));
                    make.top.equalTo(lab.mas_bottom).offset(kwt(12));
                    make.right.offset(kwt(-12));
                    make.height.offset(0.5);
                }];

                UILabel * name = [DTKTool labelWithText:@"备注：" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
                [self.GJBackview addSubview:name];
                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(lab.mas_bottom).offset(kwt(24));
                    make.left.offset(kwt(15));
                }];
                UIButton * playBtn = [UIButton new];
                self.playBtn = playBtn;
                [playBtn setImage:[UIImage imageNamed:@"language_playback0"] forState:UIControlStateNormal];
                [playBtn setImageEdgeInsets:UIEdgeInsetsMake(0, kwt(35), 0, kwt(-30))];
                [playBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, kwt(-20), 0, kwt(20))];
                playBtn.backgroundColor = KcolorHex(@"#29B560");
                [self.GJBackview addSubview:playBtn];
                playBtn.addClickBlock(^{
                    [[SYAudio shareAudio] audioPlayWithURL:model.alarmData.remark andTimeBlock:^(int time) {
                        [weakSelf opentimeWithTimes:time];
                    }];
                });
                if(model.alarmData.voiceDuration.length > 0){
                    [playBtn setTitle:[NSString stringWithFormat:@"%@",model.alarmData.voiceDuration] forState:UIControlStateNormal];
                } else  {
                    [playBtn setTitle:[NSString stringWithFormat:@"0\""] forState:UIControlStateNormal];
                }
                
                model.alarmData.openDurationBlock = ^(NSString * _Nonnull voiceDuration) {
                    weakSelf.model = weakSelf.model;
                };
                [DTKTool YJ:kwt(5) andView:playBtn];
                [self.GJBackview addSubview:playBtn];
                [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerY.equalTo(name);
                    make.left.offset(kwt(71));
                    make.width.offset(kwt(90));
                    make.height.offset(kwt(30));

                }];
                
            }
        } else {
            
            if(model.alarmData.remark.length > 0){
                
                UILabel * name = [DTKTool labelWithText:@"备注：" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
                [self.GJBackview addSubview:name];
                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(0);
                    make.left.offset(kwt(15));
                }];
                UIButton * playBtn = [UIButton new];
                self.playBtn =playBtn;
                [playBtn setImage:[UIImage imageNamed:@"language_playback0"] forState:UIControlStateNormal];
                [playBtn setImageEdgeInsets:UIEdgeInsetsMake(0, kwt(35), 0, kwt(-30))];
                [playBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, kwt(-20), 0, kwt(20))];
                playBtn.backgroundColor = KcolorHex(@"#29B560");
                [self.GJBackview addSubview:playBtn];
                playBtn.addClickBlock(^{
                    [[SYAudio shareAudio] audioPlayWithURL:model.alarmData.remark andTimeBlock:^(int time) {
                        [weakSelf opentimeWithTimes:time];
                    }];
                });
                if(model.alarmData.voiceDuration.length > 0){
                    [playBtn setTitle:[NSString stringWithFormat:@"%@",model.alarmData.voiceDuration] forState:UIControlStateNormal];
                } else  {
                    [playBtn setTitle:[NSString stringWithFormat:@"0\""] forState:UIControlStateNormal];
                }
                
                model.alarmData.openDurationBlock = ^(NSString * _Nonnull voiceDuration) {
                    weakSelf.model = weakSelf.model;
                };
                [DTKTool YJ:kwt(5) andView:playBtn];
                [self.GJBackview addSubview:playBtn];
                [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerY.equalTo(name);
                    make.left.offset(kwt(71));
                    make.width.offset(kwt(90));
                    make.height.offset(kwt(30));
                    
                }];
                
            } else {
                UILabel * name = [DTKTool labelWithText:@"/" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
                [self.GJBackview addSubview:name];
                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(0);
                    make.left.offset(kwt(15));
                }];
            }
        }
    } else if(model.alarmDataType == 2){///3行任务文本
        UILabel * lab = [DTKTool labelWithText:@"任务名称：" andFont:kFont(17) andTextColor:KcolorHex(@"#656565")];
        [self.GJBackview addSubview:lab];
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(12));
            make.top.offset(0);
            make.right.offset(kwt(-12));
//            make.height.offset(kwt(17));
        }];
        
        UILabel * taskName = [DTKTool labelWithText:model.alarmData.taskName andFont:kFont(17) andTextColor:KcolorHex(@"#222222")];
        taskName.numberOfLines = 0;
        [self.GJBackview addSubview:taskName];
        [taskName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.offset(kwt(255));
            make.top.offset(0);
            make.right.offset(kwt(-12));
            make.height.offset(model.alarmData.taskNameStrH);
        }];
        
        UILabel * lab1 = [DTKTool labelWithText:@"执行时间：" andFont:kFont(17) andTextColor:KcolorHex(@"#656565")];
        [self.GJBackview addSubview:lab1];
        [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(12));
            make.top.equalTo(taskName.mas_bottom).offset(kwt(12));
            make.right.offset(kwt(-12));
//            make.height.offset(kwt(17));
        }];
        
        
        UILabel * executeTime = [DTKTool labelWithText:model.alarmData.executeTime andFont:kFont(17) andTextColor:KcolorHex(@"#222222")];
        executeTime.numberOfLines = 0;
        [self.GJBackview addSubview:executeTime];
        [executeTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.offset(kwt(255));
            make.top.equalTo(lab1);
            make.right.offset(kwt(-12));
            make.height.offset(model.alarmData.executeTimeStrH);
        }];
        
        if(model.alarmData.executor.length > 0){

            UILabel * lab2 = [DTKTool labelWithText:@"执行人员：" andFont:kFont(17) andTextColor:KcolorHex(@"#656565")];
            lab2.numberOfLines = 0;
            [self.GJBackview addSubview:lab2];
            [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(kwt(12));
                make.top.equalTo(executeTime.mas_bottom).offset(kwt(12));
                make.right.offset(kwt(-12));
                //            make.height.offset(kwt(17));
            }];
            
            UILabel * executor = [DTKTool labelWithText:model.alarmData.executor andFont:kFont(17) andTextColor:KcolorHex(@"#222222")];
            executor.numberOfLines = 0;
            [self.GJBackview addSubview:executor];
            [executor mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.offset(kwt(255));
                make.top.equalTo(lab2);
                make.right.offset(kwt(-12));
                make.height.offset(model.alarmData.executorStrH);
            }];
        }
        
        
    } else if(model.alarmDataType == 1){
        CGFloat Y = 0;
        for (alarmDataModel * dataModel in model.alarmDataList) {
            if(dataModel.children > 0){//有子集
                UIView * line = [UIView new];
                line.backgroundColor = KcolorHex(@"#D8D8D8");
                [self.GJBackview addSubview:line];
                [line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(kwt(12));
                    make.top.offset(Y);
                    make.right.offset(kwt(-12));
                    make.height.offset(0.5);
                }];
                
                UILabel * lab = [DTKTool labelWithText:[NSString stringWithFormat:@"%@：",dataModel.name]  andTextColor:KcolorHex(@"#222222") andFont:kFont(17)];
                [self.GJBackview addSubview:lab];
                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(kwt(12));
                    make.top.offset(Y);
                    make.right.offset(kwt(-12));
                    make.height.offset(kwt(43));
                }];
                Y += kwt(43);
                
                for (alarmDataModel * childrenModel in dataModel.children) {
                    UILabel * childrenlab = [UILabel new];
                    childrenlab.numberOfLines = 0;
                    childrenlab.attributedText = childrenModel.msStr;
                    childrenlab.textAlignment = NSTextAlignmentLeft;
                    [self.GJBackview addSubview:childrenlab];
                    [childrenlab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.left.offset(12);
                        make.top.offset(Y);
                        make.right.offset(-12);
                        make.height.offset(childrenModel.msStrH);
                    }];
                    Y += childrenModel.msStrH + kwt(14);
                }
            } else {
                UILabel * lab = [UILabel new];
                lab.numberOfLines = 0;
                lab.attributedText = dataModel.msStr;
                [self.GJBackview addSubview:lab];
                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(kwt(12));
                    make.top.offset(Y);
                    make.right.offset(kwt(-12));
                    make.height.offset(dataModel.msStrH);
                }];
                Y += dataModel.msStrH + kwt(14);
            }
        }
        
    }
    
    [self.GJview mas_updateConstraints:^(MASConstraintMaker *make) {
       
        make.height.offset(model.GJviewH);
    }];
    
    [self.CLBackview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat leftY = 0;
    UIImageView * oldImg;
    for (alarmProcessRecordModel * recordModel in model.alarmProcessRecord) {///告警记录
        ///左边画个标
        UIImageView * img = kimageView(@"complete");
        [DTKTool YJBK:kwt(9) andView:img andWidth:kwt(1.5) andColor:KcolorHex(@"#90B5FA")];
        [self.CLBackview addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(10));
            make.width.height.offset(kwt(18));
            make.top.offset(leftY);
        }];
        if(recordModel != model.alarmProcessRecord.firstObject){
            UIView * line = [UIView new];
            line.backgroundColor= KcolorHex(@"#BED1F4");
            [self.CLBackview addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(img);
                make.width.offset(1);
                make.top.equalTo(oldImg.mas_bottom);
                make.bottom.equalTo(img.mas_top);
            }];
        }
        oldImg = img;

        UILabel * name = [DTKTool labelWithText:recordModel.user andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
        name.numberOfLines = 0;
        [self.CLBackview addSubview:name];
        [name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(35));
            make.top.offset(leftY);
            make.width.offset(kwt(300) - recordModel.createTimeW);
            make.height.offset(recordModel.userH);
        }];
        UILabel * createTime = [DTKTool labelWithText:recordModel.createTime andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
        [self.CLBackview addSubview:createTime];
        createTime.mas_KLS().mas_KYS();
        [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(kwt(-10));
//            make.left.equalTo(name.mas_right).offset(kwt(15));
//            make.width.offset(recordModel.createTimeW);
            make.top.offset(leftY);
        }];
        
        UIView * backview = [UIView new];
        backview.backgroundColor = KcolorHex(@"#F7F7F9");
        [DTKTool YJ:kwt(5) andView:backview];
        [self.CLBackview addSubview:backview];
        [backview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(leftY + recordModel.userH + kwt(8));
            make.left.offset(kwt(35));
            make.right.offset(kwt(-10));
            make.height.offset(recordModel.backviewH);
        }];
        ///类型 1:新增任务 2:打卡记录 3:关闭 4:审批进程
        if(recordModel.type == 1){//新增任务
            CGFloat tempY = kwt(10);
            for (alarmProcessDetailModel * dateilModel in recordModel.detailList) {
                UILabel * lab = [UILabel new];
                lab.numberOfLines = 0;
                lab.textAlignment = NSTextAlignmentLeft;
                lab.attributedText = dateilModel.xzrwStr;
                [backview addSubview:lab];
                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(tempY);
                    make.left.offset(kwt(8));
                    make.width.offset(kwt(298));
                    make.height.offset(dateilModel.xzrwStrH);
                }];
                tempY+= kwt(10) + dateilModel.xzrwStrH;
                
                UIView * line = [UIView new];
                line.backgroundColor = KcolorHex(@"#D8D8D8");
                [backview addSubview:line];
                [line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(tempY);
                    make.left.offset(kwt(8));
                    make.width.offset(kwt(298));
                    make.height.offset(0.5);
                }];
                tempY += kwt(10);
            }
        } else if(recordModel.type == 2){//:打卡记录
            CGFloat tempY = kwt(10);
            UILabel * temp = [UILabel new];
            temp.attributedText = recordModel.dkrwStr;
            [backview addSubview:temp];
            [temp mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(tempY);
                make.left.offset(kwt(8));
                make.width.offset(kwt(298));
                make.height.offset(recordModel.dkrwStrH);
            }];
            tempY += kwt(10) + recordModel.dkrwStrH;
            CGFloat btnH = 0;
            if(recordModel.detail.CopytaskDetailModelList.count > 1){
                btnH = Kwt(40);
            }
            ///打卡任务
            for (taskDetailModelListModel * listmodel in recordModel.detail.CopytaskDetailModelList) {///其实就是鱼塘数据
                UIView * tempview = [UIView new];
                tempview.backgroundColor = UIColor.whiteColor;
                
                if(listmodel.isSQ){
                    tempview.frame = CGRectMake(kwt(8), tempY, kwt(298),  kwt(40));
                } else {
                    tempview.frame = CGRectMake(kwt(8), tempY, kwt(298), listmodel.strH + kwt(16) + btnH);
                }
                [backview addSubview:tempview];
//                 创建CAShapeLayer用于绘制虚线边框
                CAShapeLayer *shapeLayer = [CAShapeLayer layer];
                shapeLayer.frame = tempview.bounds;
                // 使用UIBezierPath创建圆角矩形路径
                UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:tempview.bounds cornerRadius:kwt(3)];
                // 设置形状层的路径
                shapeLayer.path = path.CGPath;
                // 设置虚线样式
                shapeLayer.strokeColor = KcolorHex(@"#C2C2C2").CGColor; // 边框颜色
                shapeLayer.lineWidth = 0.5; // 边框宽度
                shapeLayer.lineDashPattern = @[@3, @3]; // 定义虚线模式，这里是4个单位的线，接着4个单位的空
                // 设置填充颜色为空，因为我们只需要边框
                shapeLayer.fillColor = [UIColor clearColor].CGColor;
                // 添加到视图的layer上
                [tempview.layer addSublayer:shapeLayer];
                
                if(btnH > 0){
                    
                    UILabel * pondlab = [DTKTool labelWithText:listmodel.name andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
                    [tempview addSubview:pondlab];
                    [pondlab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(kwt(13));
                        make.left.offset(kwt(8));
                        make.height.offset(kwt(14));
                    }];
                    
                    
                    gywbtn * sxBtn = [gywbtn buttonWithType:0];
                    sxBtn.infoDict = @{@"model":listmodel};
                    sxBtn.addTarget(self,@selector(openSXBtnClick:));
                    sxBtn.selected = listmodel.isSQ;
                    [sxBtn setImage:[UIImage imageNamed:@"template_expand"] forState:UIControlStateNormal];
                    [sxBtn setImage:[UIImage imageNamed:@"template_retract"] forState:UIControlStateSelected];
                    [tempview addSubview:sxBtn];
                    [sxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.centerY.equalTo(pondlab);
                        make.width.height.offset(kwt(20));
                        make.right.offset(kwt(-14));
                    }];
                    
                    
                } 
               
                if(listmodel.isSQ == YES && btnH > 0){
                    tempY += kwt(8)  + btnH;
                } else {
                    UILabel * lab = [UILabel new];
                    lab.numberOfLines = 0;
                    lab.textAlignment = NSTextAlignmentLeft;
                    lab.attributedText = listmodel.str;
                    [tempview addSubview:lab];
                    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(kwt(8) + btnH);
                        make.left.offset(kwt(8));
                        make.width.offset(kwt(272));
                        make.height.offset(listmodel.strH);
                    }];
                    tempY += kwt(8 + 20) + listmodel.strH + btnH;

                }
             
            }
            
            if(recordModel.detail.cardImgArray.count > 0){
                UILabel * name = [DTKTool labelWithText:@"打卡照片" andFont:kCFont(13) andTextColor:KcolorHex(@"#222222")];
                [backview addSubview:name];
                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(tempY);
                    make.left.offset(kwt(8));
                }];
                tempY += kwt(20);
                CGFloat X = kwt(8);
                int i = 0;
                for (NSString * phone in recordModel.detail.cardImgArray) {
                    UIImageView * img = [UIImageView new];
                    [DTKTool YJ:kwt(3) andView:img];
                    img.addClickBlock(^{
                        [weakSelf openTPwithArray:recordModel.detail.cardImgArray andview:img andIndex:i];
                    });
                    [img LZsetImageWithImagePath:phone placeholderImage:[UIImage imageNamed:@"tangkou_photo"]];
                    [backview addSubview:img];
                    [img mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(tempY);
                        make.left.offset(X);
                        make.width.height.offset(kwt(52));
                    }];
                    X += kwt(60);
                    if(X >= kwt(315)){
                        X = kwt(8);
                        tempY += kwt(60);
                    }
                    i++;
                }
                tempY += kwt(60);
            }
            
            if(recordModel.detail.voiceUrl.length > 0){
                UIView * llview = [UIView new];
                llview.frame = CGRectMake(kwt(8), tempY, kwt(268), kwt(40));
                [backview addSubview:llview];
//                 创建CAShapeLayer用于绘制虚线边框
                CAShapeLayer *shapeLayer = [CAShapeLayer layer];
                shapeLayer.frame = llview.bounds;
                
                // 使用UIBezierPath创建圆角矩形路径
                UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:llview.bounds cornerRadius:kwt(3)];
                
                // 设置形状层的路径
                shapeLayer.path = path.CGPath;
                
                // 设置虚线样式
                shapeLayer.strokeColor = KcolorHex(@"#C2C2C2").CGColor; // 边框颜色
                shapeLayer.lineWidth = 0.5; // 边框宽度
                shapeLayer.lineDashPattern = @[@3, @3]; // 定义虚线模式，这里是4个单位的线，接着4个单位的空
                
                // 设置填充颜色为空，因为我们只需要边框
                shapeLayer.fillColor = [UIColor clearColor].CGColor;
                
                // 添加到视图的layer上
                [llview.layer addSublayer:shapeLayer];
                
                UILabel * name = [DTKTool labelWithText:@"备注：" andFont:kCFont(14) andTextColor:KcolorHex(@"#222222")];
                [llview addSubview:name];
                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerY.offset(0);
                    make.left.offset(kwt(15));
                }];
                UIButton * playBtn = [UIButton new];
                [playBtn setImage:[UIImage imageNamed:@"language_playback0"] forState:UIControlStateNormal];
                [playBtn setImageEdgeInsets:UIEdgeInsetsMake(0, kwt(35), 0, kwt(-30))];
                [playBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, kwt(-20), 0, kwt(20))];
                playBtn.backgroundColor = KcolorHex(@"#29B560");
                [self addSubview:playBtn];
                self.playBtn = playBtn;
                playBtn.addClickBlock(^{
                    [[SYAudio shareAudio] audioPlayWithURL:recordModel.detail.voiceUrl andTimeBlock:^(int time) {
                        [weakSelf opentimeWithTimes:time];
                    }];
                });
                if(recordModel.detail.voiceDuration.length > 0){
                    [playBtn setTitle:[NSString stringWithFormat:@"%@",recordModel.detail.voiceDuration] forState:UIControlStateNormal];
                } else  {
                    [playBtn setTitle:[NSString stringWithFormat:@"0\"",recordModel.detail.voiceDuration] forState:UIControlStateNormal];
                }
                
//                playBtn.addTarget(self,@selector(openplay));
                recordModel.detail.openDurationBlock = ^(NSString * _Nonnull voiceDuration) {
                    weakSelf.model = weakSelf.model;
                };
                [DTKTool YJ:kwt(5) andView:playBtn];
                [llview addSubview:playBtn];
                [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerY.offset(0);
                    make.left.offset(kwt(71));
                    make.width.offset(kwt(90));
                    make.height.offset(kwt(30));

                }];
            }
            
        } else if(recordModel.type == 3){//3:关闭
            UILabel * lab = [UILabel new];
            lab.numberOfLines = 0;
            lab.textAlignment = NSTextAlignmentLeft;
            lab.attributedText = recordModel.shrwStr;
            [backview addSubview:lab];
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(kwt(10));
                make.left.offset(kwt(8));
                make.width.offset(kwt(298));
                make.height.offset(recordModel.shrwStrH);
            }];
            
        } else if(recordModel.type == 4){///:审批进程
            UILabel * lab = [UILabel new];
            lab.numberOfLines = 0;
            lab.textAlignment = NSTextAlignmentLeft;
            lab.attributedText = recordModel.shrwStr;
            [backview addSubview:lab];
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(kwt(10));
                make.left.offset(kwt(8));
                make.width.offset(kwt(298));
                make.height.offset(recordModel.shrwStrH);
            }];
            
        }
       
        leftY += recordModel.backviewH + recordModel.userH + kwt(8);
    }
    
    
    
    
    [self.CLview mas_updateConstraints:^(MASConstraintMaker *make) {
        if(model.GJviewH > 0){
            make.top.equalTo(self.GJview.mas_bottom).offset(kwt(10));
        } else {
            make.top.offset(0);
        }
        make.height.offset(model.CLviewH);
    }];
    
    if(self.timer.isValid){
        [_timer invalidate];
    }
    _timer=nil;
    [self.playBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"language_playback0"]] forState:UIControlStateNormal];

}

- (void)opentimeWithTimes:(int)times{
    if(self.timer.isValid){
        [_timer invalidate];
    }
    _timer=nil;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1/3.0 target:self selector:@selector(openAudio) userInfo:nil repeats:YES];
    self.timeS = times * 3;
}
- (void)openAudio{
    self.timeS --;
    [self.playBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"language_playback%d",self.timeS%3]] forState:UIControlStateNormal];
    if(self.timeS < 0){
        if(self.timer.isValid){
            [_timer invalidate];
        }
        _timer=nil;
        [self.playBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"language_playback0"]] forState:UIControlStateNormal];
    }
}
- (void)openSXBtnClick:(gywbtn *)btn{
    taskDetailModelListModel * model = [btn.infoDict objectForKey:@"model"];
    model.isSQ = !model.isSQ;
    if(self.openReloadBlock){
        self.openReloadBlock();
    }
}

- (void)openTPwithArray:(NSArray *)array andview:(UIView *)view andIndex:(int)index{
    [DTKTool openImagAndVideo:array andopenview:view andIndex:index];
}
@end
